//
// Created by Administrator on 2020/7/8.
//T5章:数组、指针与字符串
//数组的定义与初始化
//一维数组应用举例
//例:循环从键盘读入若干组选择题答案,计算并输出每组答案的正确率,直到输入ctrl+Z为止
//   每组连续输入5个答案,每个答案可以是"a".."d"
#include <iostream>
using namespace std;
int main()
{
    const char key[]={'a','c','b','a','d'};
    const int NUM_QUES=5;
    char c;
    int ques=0,numCorrect=0;
    cout<<"Enter the"<<NUM_QUES<<"question tests:"<<endl;
    while (cin.get(c))
    {
        if(c!='\n')//键盘回车键
        {
            if(c==key[ques])//答对了
            {
                numCorrect++;
                cout<<" ";
            }
            else//答错了
                cout<<"*";
            ques++;
        }
        else
        {
            cout<<"Score"<< static_cast<float>(numCorrect)/NUM_QUES*100<<"%";
            ques=0;
            numCorrect=0;
            cout<<endl;
        }
    }
    return 0;
}